package com.atguigu.mall.mallproduct.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.mall.mallproduct.dao.PmsBrandDao;
import com.atguigu.mall.mallproduct.entity.PmsBrandEntity;
import com.atguigu.mall.mallproduct.service.PmsBrandService;

@Service("pmsBrandService")
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandDao, PmsBrandEntity>
    implements PmsBrandService {

  @Override
  public PageUtils queryPage(Map<String, Object> params) {
    // 1.获取key
    String key = (String) params.get("key");
    QueryWrapper<PmsBrandEntity> queryWrapper = new QueryWrapper<>();
    if (!StringUtils.isEmpty(key)) {
      queryWrapper.eq("brand_id", key).or().like("name", key);
    }
    IPage<PmsBrandEntity> page =
        this.page(new Query<PmsBrandEntity>().getPage(params), queryWrapper);
    return new PageUtils(page);
  }
}
